<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "mall_material_menu".
 *
 * @property int $id
 * @property string $title 菜单名
 * @property string $des 备注
 * @property int $sort 排序
 * @property int $status -1禁用 1启用
 * @property int $create_time 创建时间
 * @property int $parent_id 父id
 * @property string $cover_url 封面图 二级菜单才有
 * @property int $rank 菜单级别
 	
 */
class MallMaterialMenu extends \yii\db\ActiveRecord
{

    const SCENARIO_DEFAULT = 'default';
    const SCENARIO_UPLOAD = 'upload';
    public $file;

    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'mall_material_menu';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['title'], 'required'],
            [['sort', 'pid','status', 'create_time', 'parent_id', 'rank'], 'integer'],
            [['cover_url'], 'string'],
            ['parent_id', 'default', 'value' => 0],
            [['title'], 'string', 'max' => 20],
            [['des'], 'string', 'max' => 30],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'title' => '分类名称',
            'des' => '说明',
            'sort' => '排序',
            'status' => '状态',
            'create_time' => '时间',
            'parent_id' => '父菜单',
            'cover_url' => '二级菜单封面图',
            'rank' => '菜单级别',
        ];
    }

    public static function attributeValue()
    {
        return [
            'status' => [
                '1' => '启用',
                '-1' => '禁用'
            ],
            'rank' => [
                '1' => '一级菜单',
                '2' => '二级菜单',
            ],
        ];
    }

    public function getStatus()
    {
        switch($this->status)
        {
            case -1:
                $value = '禁用';
                break;
            case 1:
                $value = '启用';
                break;
            default:
                $value = '未知';
                break;
        }
        return $value;
    }

    public function scenarios()
    {
        $scenarios =  parent::scenarios();
        $scenarios[self::SCENARIO_DEFAULT] = ['id', 'title', 'desc', 'sort', 'status', 'create_time', 'parent_id', 'cover_url', 'rank'];
        $scenarios[self::SCENARIO_UPLOAD] = ['file'];
        return $scenarios;
    }
}
